﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace jnxcLogin
{
    public partial class EditUser : System.Web.UI.Page
    {
        Maticsoft.BLL.UserInfo um = new Maticsoft.BLL.UserInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["edit_user_id"]!= null)
                {
                    int user_id = Convert.ToInt32(Session["edit_user_id"]);

                    ShowInfo(user_id);
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.lbl_user_id.Text != "")
            {
                int user_id = int.Parse(this.lbl_user_id.Text);
                Maticsoft.Model.UserInfo u = um.GetModel(user_id);

                u.loginName = this.txt_name.Text;
                if (!string.IsNullOrEmpty(txt_pass.Text))//如果密码不输入则不修改密码
                {
                    u.loginPass = txt_pass.Text;
                }
                u.remark = txt_remark.Text;

                if (um.Update(u))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.returnValue=true;parent.close();</script>");
                }
            }
            
            
        }

        private void ShowInfo(int user_id)
        {
            Maticsoft.Model.UserInfo u = um.GetModel(user_id);

            if (null != u)
            {
                this.txt_name.Text = u.loginName;
                this.txt_pass.Text = u.loginPass;
                this.txt_remark.Text = u.remark;
                this.lbl_user_id.Text = user_id.ToString();
            }
        
        }
    }
}